package starwars.example;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.camera.hud.controls.AnalogOnScreenControl;
import org.anddev.andengine.engine.camera.hud.controls.AnalogOnScreenControl.IAnalogOnScreenControlListener;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.content.Context;

public class OnScreenControl {

	public BitmapTextureAtlas mOnScreenControlTexture;
	public TextureRegion mOnScreenControlBaseTextureRegion;
	public TextureRegion mOnScreenControlKnobTextureRegion;

	
	public OnScreenControl(Scene scene,
						   Engine engine,
						   Context context,
						   Camera camera,
						   float CAMERA_WIDTH,
						   float CAMERA_HEIGHT,
						   IAnalogOnScreenControlListener listener){

		mOnScreenControlTexture = new BitmapTextureAtlas(256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		mOnScreenControlBaseTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, context, "onscreen_control_base.png", 0, 0);
		mOnScreenControlKnobTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, context, "onscreen_control_knob.png", 128, 0);

		engine.getTextureManager().loadTextures(this.mOnScreenControlTexture);

		final AnalogOnScreenControl analogOnScreenControl = 
				new AnalogOnScreenControl(0, CAMERA_HEIGHT - mOnScreenControlBaseTextureRegion.getHeight(),
										  camera,
										  mOnScreenControlBaseTextureRegion,
										  mOnScreenControlKnobTextureRegion,
										  0.1f,
										  200,
										  listener);
		

		analogOnScreenControl.getControlBase().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		analogOnScreenControl.getControlBase().setAlpha(0.5f);
		analogOnScreenControl.refreshControlKnobPosition();

		scene.setChildScene(analogOnScreenControl);
		
	}
}
